﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using KeepAnimals.BLL;
using KeepAnimals.DAL;

namespace KeepAnimals.UI
{
    public partial class FormViewAnimal : Form
    {
        private int _idDepartment;

        private int IdDepartment
        {
            get { return _idDepartment; }
            set { _idDepartment = value; }
        }
        public FormViewAnimal(string id)
        {
            InitializeComponent();
            //MessageBox.Show(id.ToString());
            int idDepartment = Int32.Parse(id);
            _idDepartment = idDepartment;
            InfoAnimal(idDepartment);
        }

        private void InfoAnimal(int id)
        {
            var animal = Animal.GetAnimalById(id);
            if (animal.IdCategory == Animal.ANIMAL_CAT)
            {
                PictureBoxImgAnimal.BackgroundImage = KeepAnimals.UI.Properties.Resources.ImgCat1;
            }
            else
            {
                PictureBoxImgAnimal.BackgroundImage = KeepAnimals.UI.Properties.Resources.ImgDog1;
            }
            PictureBoxImgAnimal.BackgroundImageLayout = ImageLayout.Stretch;

            textBoxName.Text = animal.Name;
            textBoxAge.Text = animal.Age.ToString();
            textBoxWeight.Text = animal.Weight.ToString();
            textBoxState.Text =  animal.State;
            textBoxDescription.Text = animal.Description;

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void FormViewAnimal_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            var id = IdDepartment;
            Animal animal = new Animal();
            animal.Id = id;
            animal.Name = textBoxName.Text ;
            animal.Age = Int32.Parse(textBoxAge.Text);
            animal.Weight = Double.Parse(textBoxWeight.Text) ;
            animal.State = textBoxState.Text ;
            animal.Description = textBoxDescription.Text;
            animal.UpdateAnimalInDatabase();
        
        
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            var id = IdDepartment;
            Animal.DeleteAnimalById(IdDepartment);
        }
    }
}
